// 轮播图样式重置
var swiper = new Swiper(".mySwiper", {
  spaceBetween: 30,
  centeredSlides: true,
  autoplay: {
    delay: 2500,
    disableOnInteraction: false,
  },
  pagination: {
    el: ".swiper-pagination",
    clickable: true,
  },
  navigation: {
    nextEl: ".swiper-button-next",
    prevEl: ".swiper-button-prev",
  },
});


// API服务移入移出js效果
function APIServe() {
  //需求：移入对应格子中，图片改变，字体颜色改变
  let lis = document.querySelectorAll(".API-serve .matter li")
  let imgs = document.querySelectorAll(".API-serve .matter li img")
  let ps = document.querySelectorAll(".API-serve .matter li p")
  let site = ["./images/api01-c.svg", "./images/api02-c.svg", "./images/api03-c.svg", "./images/api04-c.svg", "./images/api05-c.svg", "./images/api06-c.svg", "./images/api07-c.svg", "./images/api08-c.svg", "./images/apic1-c.svg", "./images/apic2-c.svg"]
  let imgsrc = []
  imgs.forEach((i) => {
    imgsrc.push(i.src)
  });
  lis.forEach((i, j) => {
    i.addEventListener("mouseenter", function () {
      i.style.backgroundColor = "rgb(18,113,242)"
      ps[j].style.color = "#fff"
      imgs[j].src = site[j]
    })
    i.addEventListener("mouseleave", function () {
      i.style.backgroundColor = "#fff"
      ps[j].style.color = "#000"
      imgs[j].src = imgsrc[j]
    })
  });
}
APIServe()



// 助力行业巨头轮播图
function whoServed() {
  // 需求：轮播图自动动，移入时候停止
  let lis = document.querySelectorAll(".who-served .columns li")
  let index = 0
  let timeId = null
  function lbt() {
    timeId = setInterval(() => {
      lis[index].classList.remove("on")
      index++
      if (index == 3) {
        index = 0
      }
      lis[index].classList.add("on")
    }, 1000);
  }
  lbt()

  //移入时轮播图静止
  let uls = document.querySelector(".who-served .columns ul")
  uls.addEventListener("mouseenter", function () {
    clearInterval(timeId)
    timeId = null
  })
  uls.addEventListener("mouseleave", function () {
    lbt()
  })
}
whoServed()

//助力行业巨头下面的合作企业移入移出效果
function sponsor(){
  let imgs=document.querySelectorAll(".who-served-sponsor img")
  let site=["./images/more-partners-item01.svg", "./images/more-partners-item02.svg", "./images/more-partners-item03.svg", "./images/more-partners-item04.svg", "./images/more-partners-item05.svg", "./images/more-partners-item06.svg", "./images/more-partners-item07.svg", "./images/more-partners-item08.svg"]
  let imgsrc=[]
  imgs.forEach((i) => {
    imgsrc.push(i.src)
  });
  imgs.forEach((i,j) => {
    i.addEventListener("mouseenter",function(){
      i.src=site[j]
    })
    i.addEventListener("mouseleave",function(){
      i.src=imgsrc[j]
    })
  });
}
sponsor()

//回到顶部
function tops(){
  let div=document.querySelector(".top")
  let top=document.querySelector(".top span")
  window.addEventListener("scroll",function(){
    if (document.documentElement.scrollTop>800) {
      div.style.display="block"
    }else{
      div.style.display="none"
    }
  })
  top.addEventListener("click",function(){
    let timeId=null
    timeId=setInterval(() => {
      document.documentElement.scrollTop-=40
      if (document.documentElement.scrollTop<=0) {
        clearInterval(timeId)
        timeId=null
      }
    }, 20);
  })
}
tops()